import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'dashboard', access: 'all'}
    }],
    meta: {access: 'all'}
  },
  {
    path: '/society',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Society',
        component: () => import('@/views/society/index'),
        meta: {title: '社团', icon: 'el-icon-s-promotion', access: 'admin_account'}
      }
    ],
    meta: {access: 'admin_account'}
  },
  { // 系统管理员，对社团管理员进行管理 页面
    path: '/manager',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Manager',
        component: () => import('@/views/manager/index'),
        meta: {title: '社团管理员', icon: 'user', access: 'admin_account'}
      }
    ],
    meta: {access: 'admin_account'}
  },
  {
    path: '/apply',
    component: Layout,
    redirect: '/apply/audit',
    name: 'Apply',
    meta: {title: '申请', icon: 'el-icon-postcard', access: 'admin2_account'},
    children: [
      {
        path: 'audit',
        name: 'Audit',
        component: () => import('@/views/apply/audit/index'),
        meta: {title: '审核', access: 'admin2_account'}
      },
      {
        path: 'auditlist',
        name: 'Auditlist',
        component: () => import('@/views/apply/audit_list/index'),
        meta: {title: '历史审核', access: 'admin2_account'}
      }
    ]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/ArticlePost',
    name: 'Article',
    meta: {title: '文章', icon: 'el-icon-document', access: 'admin2_account'},
    children: [
      {
        path: 'articlePost',
        name: 'ArticlePost',
        component: () => import('@/views/article/post/index'),
        meta: {title: '发布', access: 'admin2_account'}
      },
      {
        path: 'articleList',
        name: 'ArticleList',
        component: () => import('@/views/article/article_list/index'),
        meta: {title: '文章列表', access: 'admin2_account'}
      },
      {
        path: 'articleComment',
        name: 'ArticleComment',
        component: () => import('@/views/article/comment/index'),
        meta: {title: '评论管理', access: 'admin2_account'}
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/activityPost',
    name: 'Activity',
    meta: {title: '活动', icon: 'el-icon-s-flag', access: 'admin2_account'},
    children: [
      {
        path: 'activityPost',
        name: 'ActivityPost',
        component: () => import('@/views/activity/post/index'),
        meta: {title: '发布', access: 'admin2_account'}
      },
      {
        path: 'activityList',
        name: 'ActivityList',
        component: () => import('@/views/activity/list/index'),
        meta: {title: '活动列表', access: 'admin2_account'}
      },
      {
        path: 'activityInform',
        name: 'ActivityInform',
        component: () => import('@/views/activity/inform/index'),
        meta: {title: '通知管理', access: 'admin2_account'}
      },
      {
        path: 'activitySignin',
        name: 'ActivitySignin',
        component: () => import('@/views/activity/signin/index'),
        meta: {title: '活动签到', access: 'admin2_account'}
      },
    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: '/member/index',
    children: [
      {
        path: 'index',
        name: 'Member',
        component: () => import('@/views/member/index'),
        meta: {title: '社员管理', icon: 'user', access: 'admin2_account'}
      }
    ],
    meta: {access: 'admin2_account'}
  },
  {
    path: '/talk',
    component: Layout,
    redirect: '/talk/talkList',
    name: 'Talk',
    meta: {title: '讨论', icon: 'el-icon-chat-dot-square', access: 'admin2_account'},
    children: [
      {
        path: 'talkList',
        name: 'TalkList',
        component: () => import('@/views/talk/list/index'),
        meta: {title: '讨论管理', access: 'admin2_account'}
      },
      {
        path: 'talkComment',
        name: 'TalkComment',
        component: () => import('@/views/talk/comment/index'),
        meta: {title: '评论管理', access: 'admin2_account'}
      }
    ]
  },
  {
    path: '/feedback',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Feedback',
        component: () => import('@/views/feedback/index'),
        meta: {title: '反馈', icon: 'el-icon-edit', access: 'admin2_account'}
      }
    ],
    meta: {access: 'admin2_account'}
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'http://www.njtc.edu.cn/',
        meta: {title: '内师官网', icon: 'link', access: 'all'}
      }
    ],
    meta: {access: 'all'}
  },

  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
